import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.sql.Connection;
import java.sql.DriverManager;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.TableColumn;


public class MyProgressPanel extends JPanel{
        JPanel panel;
        JPanel north,center;
        String[] generalCols={"Number","Course","Completed","term","Grade","Credits"};
        Object[][] rqm = {
        		{"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""}
        };
        Object[][] grqm = {
        		{"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""}
        };
        Object[][] elc = {
        		{"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""},
                {"","","","","",""}
        };
        
        
        JTable generalT,majorT,elecT;
       
        public MyProgressPanel(){
               
               
                panel=new JPanel();
                panel.setPreferredSize(new Dimension(600,940));
                //panel.setLayout(new BorderLayout());
                panel.setBackground(Color.WHITE);
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                JScrollPane scroll=new JScrollPane(panel);//,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
                scroll.setMinimumSize(new Dimension(600,400));
                scroll.setPreferredSize(new Dimension(600,400));
               
                //north panel
                north=new JPanel();
                north.setLayout(new BorderLayout());
                north.setBackground(Color.WHITE);
               
                JPanel nnorth=new JPanel();
                JPanel cnorth=new JPanel();
                JLabel northLabel=new JLabel("At a Glance");
                nnorth.setBorder(BorderFactory.createLineBorder((Color.black)));
                nnorth.add(northLabel);
                north.add(nnorth,BorderLayout.NORTH);
               
                cnorth.setLayout(new GridLayout(6,2));
                cnorth.setPreferredSize(new Dimension(600, 60));
                cnorth.setBackground(Color.WHITE);
                JLabel cum=new JLabel("Cumulative GPA:");
                JLabel studentGPA=new JLabel(Float.toString(StudentHomePanel.totalg/StudentHomePanel.totalc));
                JLabel degree=new JLabel("Degree:");
                JLabel studentDegree=new JLabel("Bachelor of Science");
                JLabel majors=new JLabel("Majors:");
                JLabel studentMajors=new JLabel("Computer Science");
                JLabel departments=new JLabel("Departments:");
                JLabel studentDepartments=new JLabel("Computer Science");
                JLabel catalog=new JLabel("Catalog:");
                JLabel studentCatalog=new JLabel("2012");
                JLabel progress=new JLabel("Progress:");
                JLabel studentProgress=new JLabel(Integer.toString(StudentHomePanel.totalc)+"/120");
               
                cnorth.add(cum);
                cnorth.add(studentGPA);
                cnorth.add(degree);
                cnorth.add(studentDegree);
                cnorth.add(majors);
                cnorth.add(studentMajors);
                cnorth.add(departments);
                cnorth.add(studentDepartments);
                cnorth.add(catalog);
                cnorth.add(studentCatalog);
                cnorth.add(progress);
                cnorth.add(studentProgress);
                north.add(cnorth,BorderLayout.CENTER);
               
                panel.add(north,BorderLayout.NORTH);
               
               
                //center
                center=new JPanel();
                center.setLayout(new BorderLayout());
                center.setBackground(Color.white);
                center.setPreferredSize(new Dimension(600,850));
               
                JPanel ncenter=new JPanel();
                JPanel ccenter=new JPanel();
                ccenter.setLayout(new BorderLayout());
                ccenter.setBackground(Color.white);
                //
                JLabel requirements=new JLabel("Requirements");
                ncenter.setBorder(BorderFactory.createLineBorder((Color.black)));
                ncenter.add(requirements);
                center.add(ncenter,BorderLayout.NORTH);
               
                JPanel cpanels=new JPanel();
                cpanels.setLayout(new BorderLayout());
                cpanels.setPreferredSize(new Dimension(600,850));
               
                //in ccenter
                //center_north
                //general studies program
                
                //get general studies
                int earned = 0, g_required = 0;
                try{
                    String dName = "com.mysql.jdbc.Driver";
                    String url = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
                    Connection con = DriverManager.getConnection(url);
                    
                    //get general requirements
                    java.sql.Statement mysqlStatement = con.createStatement();
                    java.sql.ResultSet resultSet;
                    resultSet = mysqlStatement.executeQuery("SELECT course_number, course_name, credit_hours, CID FROM course_catalog WHERE major='GEN'");
                    
                    int i = 0;
                    while (resultSet.next()) {
                    grqm[i][0] = resultSet.getString(1);
                    grqm[i][1] = resultSet.getString(2);
                    String hours = resultSet.getString(3);
                    g_required += Integer.parseInt(hours);
                    grqm[i][5] = hours;
                    String courseID = resultSet.getString(4);
                    
                    //Get Grade
                    java.sql.Statement gradeStatement = con.createStatement();
                    java.sql.ResultSet gradeResult;
                    
                    gradeResult = gradeStatement.executeQuery("SELECT grade FROM total_course_list WHERE CID='"+courseID+"'");
                    
                    while (gradeResult.next()){
                    grqm[i][4] = gradeResult.getString(1);
                    }
                    
                    if (grqm[i][4]!="") {
                    	grqm[i][2] = "Yes";
                    	earned += Integer.parseInt(hours);
                    	
                    	if (grqm[i][4]=="A") {grqm[i][3]="Fall 2012";}
                    	if (grqm[i][4]=="B") {grqm[i][3]="Fall 2013";}
                    }
                    
                    
                    //next line
                    i = i + 1;
                    }
                    
                    con.close();
                    }
                    catch(Exception ex){}
                
                JPanel center_north=new JPanel();
                center_north.setLayout(new BorderLayout());
                JPanel cn_north=new JPanel();
               
                JLabel generallabel=new JLabel("General Studies Program");
                cn_north.setBorder(BorderFactory.createLineBorder((Color.black)));
                JPanel e1=new JPanel();
                e1.setPreferredSize(new Dimension(600,10));
                e1.setBackground(Color.white);
                cn_north.add(generallabel);
                center_north.add(cn_north,BorderLayout.NORTH);
                //cn_north.add(e1);
                e1.setLayout(new BorderLayout());
                JLabel c1=new JLabel("Credit Earned: " + earned + "/" + g_required);
                e1.add(c1,BorderLayout.PAGE_START);
               
                JPanel general=new JPanel();
                general.setLayout(new BorderLayout());
                general.setBorder(BorderFactory.createLineBorder((Color.black)));
                generalT=new JTable(grqm,generalCols);
                                TableColumn column;
                                column = generalT.getColumnModel().getColumn(1);
                                column.setPreferredWidth(200);
                                general.add(generalT.getTableHeader(), BorderLayout.PAGE_START);
                                general.add(generalT, BorderLayout.CENTER);
               
                ccenter.setPreferredSize(new Dimension(600,250));
                ccenter.add(center_north,BorderLayout.NORTH);
                ccenter.add(e1,BorderLayout.CENTER);
                ccenter.add(general,BorderLayout.SOUTH);
                cpanels.add(ccenter,BorderLayout.NORTH);
                               
                earned = 0;
                int m_required = 0;
                
                try{
                    String dName = "com.mysql.jdbc.Driver";
                    String url = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
                    Connection con = DriverManager.getConnection(url);
                   
                    //get Major
                    java.sql.Statement majorStatement = con.createStatement();
                    java.sql.ResultSet majorResult;
                    
                    majorResult = majorStatement.executeQuery("SELECT major FROM student_list WHERE SID='"+MenuPanel.SID+"'");
                    String mj = null;
                    while (majorResult.next()){
                    mj = majorResult.getString(1);}
                    
                    //get Major requirement
                    java.sql.Statement mysqlStatement = con.createStatement();
                    java.sql.ResultSet resultSet;
                    resultSet = mysqlStatement.executeQuery("SELECT course_number, course_name, credit_hours, CID FROM course_catalog WHERE (major='"+mj+"' AND elective='0')");
                    
                    int i = 0;
                    while (resultSet.next()) {
                    String elective = resultSet.getString(1);
                    System.out.println(elective);
                    //Requirements and Elective
                    
                    rqm[i][0] = resultSet.getString(1);
                    rqm[i][1] = resultSet.getString(2);
                    String hours = resultSet.getString(3);
                    m_required += Integer.parseInt(hours);
                    rqm[i][5] = hours;
                    String courseID = resultSet.getString(4);
                    
                    //Get Grade
                    java.sql.Statement gradeStatement = con.createStatement();
                    java.sql.ResultSet gradeResult;
                    
                    gradeResult = gradeStatement.executeQuery("SELECT grade FROM total_course_list WHERE CID='"+courseID+"'");
                    
                    while (gradeResult.next()){
                    rqm[i][4] = gradeResult.getString(1);}
                    
                    if (rqm[i][4]!="") {earned += Integer.parseInt(hours); rqm[i][2] = "Yes"; rqm[i][3]="Fall 2014";}
                    
                    
                    //next line
                    i = i + 1;
                    }
                    
                    con.close();
                    }
                    catch(Exception ex){}
                
                
                //gmajor studies program
                JPanel ccenter2=new JPanel();
                ccenter2.setLayout(new BorderLayout());
                ccenter2.setBackground(Color.white);
                                JPanel center_north2=new JPanel();
                                center_north2.setLayout(new BorderLayout());
                                JPanel cn_north2=new JPanel();
                               
                                JLabel generallabel2=new JLabel("Majors Requirement");
                                cn_north2.setBorder(BorderFactory.createLineBorder((Color.black)));
                                JPanel e2=new JPanel();
                                e2.setPreferredSize(new Dimension(600,10));
                                e2.setBackground(Color.white);
                                cn_north2.add(generallabel2);
                                center_north2.add(cn_north2,BorderLayout.NORTH);
                                //cn_north.add(e1);
                                e2.setLayout(new BorderLayout());
                                JLabel c2=new JLabel("Credit Earned: " + earned + "/" + m_required);
                                e2.add(c2,BorderLayout.PAGE_START);
                               
                                JPanel general2=new JPanel();
                                general2.setLayout(new BorderLayout());
                                general2.setBorder(BorderFactory.createLineBorder((Color.black)));
                                majorT=new JTable(rqm,generalCols);
                                                //TableColumn column;
                                                column = majorT.getColumnModel().getColumn(1);
                                                column.setPreferredWidth(200);
                                                general2.add(majorT.getTableHeader(), BorderLayout.PAGE_START);
                                                general2.add(majorT, BorderLayout.CENTER);
                                ccenter2.setPreferredSize(new Dimension(600,250));
                                ccenter2.add(center_north2,BorderLayout.NORTH);
                                ccenter2.add(e2,BorderLayout.CENTER);
                                ccenter2.add(general2,BorderLayout.SOUTH);
                                cpanels.add(ccenter2,BorderLayout.CENTER);
                               
                               
                                earned = 0;
                                //electives studies program
                                try{
                                    String dName = "com.mysql.jdbc.Driver";
                                    String url = "jdbc:mysql://db4free.net:3306/studentreg14?user=studentreg14&password=KCTSkcts";
                                    Connection con = DriverManager.getConnection(url);
                                   
                                    //get Major
                                    java.sql.Statement majorStatement = con.createStatement();
                                    java.sql.ResultSet majorResult;
                                    
                                    majorResult = majorStatement.executeQuery("SELECT major FROM student_list WHERE SID='"+MenuPanel.SID+"'");
                                    String mj = null;
                                    while (majorResult.next()){
                                    mj = majorResult.getString(1);}
                                    
                                    //get Major requirement
                                    java.sql.Statement mysqlStatement = con.createStatement();
                                    java.sql.ResultSet resultSet;
                                    resultSet = mysqlStatement.executeQuery("SELECT course_number, course_name, credit_hours, CID FROM course_catalog WHERE (major='"+mj+"' AND elective='1')");
                                    
                                    int i = 0;
                                    while (resultSet.next()) {
                                    String elective = resultSet.getString(1);
                                    System.out.println(elective);
                                    //Requirements and Elective
                                    
                                    elc[i][0] = resultSet.getString(1);
                                    elc[i][1] = resultSet.getString(2);
                                    String hours = resultSet.getString(3);
                                    m_required += Integer.parseInt(hours);
                                    elc[i][5] = hours;
                                    String courseID = resultSet.getString(4);
                                    
                                    //Get Grade
                                    java.sql.Statement gradeStatement = con.createStatement();
                                    java.sql.ResultSet gradeResult;
                                    
                                    gradeResult = gradeStatement.executeQuery("SELECT grade FROM total_course_list WHERE CID='"+courseID+"'");
                                    
                                    while (gradeResult.next()){
                                    elc[i][4] = gradeResult.getString(1);}
                                    
                                    if (elc[i][4]!="") {earned += Integer.parseInt(hours); elc[i][2] = "Yes"; elc[i][3]="Fall 2014";}
                                    
                                    
                                    //next line
                                    i = i + 1;
                                    }
                                    
                                    con.close();
                                    }
                                    catch(Exception ex){}
                                
                                //add
                                JPanel ccenter3=new JPanel();
                                ccenter3.setLayout(new BorderLayout());
                                ccenter3.setBackground(Color.white);
                                                JPanel center_north3=new JPanel();
                                                center_north3.setLayout(new BorderLayout());
                                                JPanel cn_north3=new JPanel();
                                               
                                                JLabel generallabel3=new JLabel("Electives");
                                                cn_north3.setBorder(BorderFactory.createLineBorder((Color.black)));
                                                JPanel e3=new JPanel();
                                                e3.setPreferredSize(new Dimension(600,10));
                                                e3.setBackground(Color.white);
                                                cn_north3.add(generallabel3);
                                                center_north3.add(cn_north3,BorderLayout.NORTH);
                                                //cn_north.add(e1);
                                                e3.setLayout(new BorderLayout());
                                                JLabel c3=new JLabel("Credit Earned: " + earned + "/" + (120-g_required-m_required));
                                                e3.add(c3,BorderLayout.PAGE_START);
                                               
                                                JPanel general3=new JPanel();
                                                general3.setLayout(new BorderLayout());
                                                general3.setBorder(BorderFactory.createLineBorder((Color.black)));
                                                elecT=new JTable(elc,generalCols);
                                                                //TableColumn column;
                                                                column = elecT.getColumnModel().getColumn(1);
                                                                column.setPreferredWidth(200);
                                                                general3.add(elecT.getTableHeader(), BorderLayout.PAGE_START);
                                                                general3.add(elecT, BorderLayout.CENTER);
                                                ccenter3.setPreferredSize(new Dimension(600,250));
                                                ccenter3.add(center_north3,BorderLayout.NORTH);
                                                ccenter3.add(e3,BorderLayout.CENTER);
                                                ccenter3.add(general3,BorderLayout.SOUTH);
                                                cpanels.add(ccenter3,BorderLayout.SOUTH);
               
               
               
                center.add(cpanels,BorderLayout.CENTER);
               
                JPanel bott=new JPanel();
                bott.setPreferredSize(new Dimension(600,90));
               
               
                panel.add(center,BorderLayout.CENTER);
                panel.add(bott,BorderLayout.SOUTH);
               
                //add(panel);
                add(scroll);
        }
}

